<?php
declare (strict_types = 1);
namespace app\admin\model\finance;

use app\common\model\BaseModel;
use think\facade\Request;
use app\user\logic\user\Account as User;

/**
 * 提现模型
 */
class Encashment extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'user_encashment';

    /**
     * 设置自动写入时间
     * @var boolean
     */
    protected $autoWriteTimestamp = true;

    /**
     * 时间显示格式
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';

    /**
     * 定义表主键
     * @var string
     */
    protected $pk = 'order_no';

    // 定义全局的查询范围
    protected $globalScope = ['mhm'];

    // protected static $type_text = ['余额','微信','支付宝','银行卡'];
    // public function getTypeAttr($value)
    // {
    //     return static::$type_text[$value];
    // }

    public function scopeWait($query)
    {
        $query->where('status', 1);
    }

    public function scopeDone($query)
    {
        $query->where('status', 2);
    }

    public function scopeReject($query)
    {
        $query->where('status', 3);
    }

    public function scopeMhm($query)
    {
        $query->where('mhm_id', request()->mhm_id);
    }

    public function userName()
    {
        return $this->belongsTo(User::class)->bind(['user_name']);
    }
}
